package nioTest;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 名称: ReadTextByNIO.java <br>
 * 描述: <br>
 * 最近修改时间:2018/5/4 16:14 <br>
 *
 * @version [版本号, V1.0]
 * @since 2018/5/4 16:14
 * @author zhipingzhang  
 */
public class ReadTextByNIO {

    private static ExecutorService executorService = Executors.newFixedThreadPool(50);

    public static void main(String[] args) throws Exception {
        executorService.execute(() -> {

        });
        RandomAccessFile aFile = new RandomAccessFile("C:\\Users\\zhipingzhang\\Desktop\\worklist\\20180410多租户改造二期\\生产配置\\" +
                "20180420-P-084046\\prd-config\\admin-server\\bootstrap.yml", "rw");


        FileChannel inChannel = aFile.getChannel();

        ByteBuffer buf = ByteBuffer.allocate(48);

        int bytesRead = inChannel.read(buf);

        while (bytesRead != -1) {

            System.out.println("Read " + bytesRead + "\n");
            System.out.println("position " + buf.position() + "\n");
            System.out.println("capacity " + buf.capacity() + "\n");
            buf.flip();

            while (buf.hasRemaining()) {
                System.out.print((char) buf.get());
            }
            buf.clear();
            bytesRead = inChannel.read(buf);
        }
        aFile.close();
    }
}
